var webfont = {
    callback_args : {},
    basepath : "<?php echo Common::httpUri('/subset', $_SERVER['HTTP_HOST']); ?>",
    load : function(options, callback) {
        options['callback_id'] = Math.random();
        if (callback) {
            webfont.callback_args[options['callback_id']] = callback;
        }
        var s = document.createElement('script');
        s.type = "text/javascript";
        s.async = true;
        var _url = '?nocache=' + Math.random();
        for (var key in options) {
            _url += "&" + encodeURI(key) + "=" + encodeURI(options[key]);
        }
        s.src = webfont.basepath + _url;
        (document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(s);

    },
    callback : function(id) {
        if (webfont.callback_args[id]) {
            webfont.callback_args[id]();
        }
    },
    parse : function(font_name) {
        var str = document.body.textContent || document.body.innerText;
        str = str.split("\r").join("").split("\n").join("").split(" ").join();
        var reg = /(.)(?=.*\1)/g;
        str = str.replace(reg, "");
        if (str.length > 800) {
            str = str.substring(0, 800);
        }
        webfont.load({"name":font_name, "subset": str}, function(){

        });
    },
    custom : function(font_name, subset, callback) {
        subset = subset.split("\r").join("").split("\n").join("").split(" ").join("");
        var reg = /(.)(?=.*\1)/g;
        subset = subset.replace(reg, "");
        if (subset.length > 800) {
            subset = subset.substring(0, 800);
        }
        webfont.load({"name":font_name, "subset": subset}, callback)
    }
}